/*
 * @Author: lininghua 0027012803@iwhalecloud.com
 * @Date: 2022-05-10 00:20:21
 * @LastEditors: lininghua 0027012803@iwhalecloud.com
 * @LastEditTime: 2022-05-12 15:12:20
 * @FilePath: /flowplatform-fe-sf/src/pages/flowmonitor/eventlist/models/log.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { handlePay } from "../services";
import { handleBatchCompensation } from "../services";

const initData = {
  query: {
    modelKey: "",
    modelName: "",
    timeStart: "",
    timeEnd: "",
  },
};

export default {
  namespace: "event",
  state: {
    ...initData,
  },
  effects: {
    *updateState({ payload }, { put }) {
      const resp = yield put({
        type: "save",
        payload: {
          query: payload,
        },
      });
      return resp;
    },
    *handlePay({ payload }, { call }) {
      const { datas = {}, errCode, errMsg, errortext } = yield call(
        handlePay,
        payload
      );
      return { errCode, errMsg: errMsg || errortext, datas };
    },
    *handleBatchCompensation({ payload }, { call }) {
      const { datas = {}, errCode, errMsg, errortext } = yield call(
        handleBatchCompensation,
        payload
      );
      return { errCode, errMsg: errMsg || errortext, datas };
    },
  },
  reducers: {
    save: (state, { payload }) => ({
      ...state,
      ...payload,
    }),
    clearData: () => ({ ...initData }),
  },
};
